from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-10-16 14:04:31.574144
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 16, Oct, 2022
Time: 14:04:40
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.7266
Nobs: 811.000 HQIC: -51.0478
Log likelihood: 10514.2 FPE: 5.53738e-23
AIC: -51.2479 Det(Omega_mle): 4.95911e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.295768 0.052499 5.634 0.000
L1.Burgenland 0.109080 0.035346 3.086 0.002
L1.Kärnten -0.106423 0.018821 -5.655 0.000
L1.Niederösterreich 0.210358 0.073926 2.846 0.004
L1.Oberösterreich 0.099632 0.070915 1.405 0.160
L1.Salzburg 0.250784 0.037649 6.661 0.000
L1.Steiermark 0.038628 0.049287 0.784 0.433
L1.Tirol 0.106318 0.039974 2.660 0.008
L1.Vorarlberg -0.058910 0.034370 -1.714 0.087
L1.Wien 0.059262 0.063231 0.937 0.349
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.063393 0.108670 0.583 0.560
L1.Burgenland -0.033685 0.073163 -0.460 0.645
L1.Kärnten 0.047778 0.038958 1.226 0.220
L1.Niederösterreich -0.172441 0.153023 -1.127 0.260
L1.Oberösterreich 0.385130 0.146789 2.624 0.009
L1.Salzburg 0.286651 0.077932 3.678 0.000
L1.Steiermark 0.105843 0.102021 1.037 0.300
L1.Tirol 0.313548 0.082745 3.789 0.000
L1.Vorarlberg 0.025401 0.071143 0.357 0.721
L1.Wien -0.014985 0.130883 -0.114 0.909
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189861 0.026952 7.044 0.000
L1.Burgenland 0.090187 0.018146 4.970 0.000
L1.Kärnten -0.008433 0.009662 -0.873 0.383
L1.Niederösterreich 0.264525 0.037952 6.970 0.000
L1.Oberösterreich 0.126445 0.036406 3.473 0.001
L1.Salzburg 0.047923 0.019329 2.479 0.013
L1.Steiermark 0.017120 0.025303 0.677 0.499
L1.Tirol 0.094361 0.020522 4.598 0.000
L1.Vorarlberg 0.059323 0.017645 3.362 0.001
L1.Wien 0.119727 0.032461 3.688 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.109870 0.027615 3.979 0.000
L1.Burgenland 0.044247 0.018592 2.380 0.017
L1.Kärnten -0.016108 0.009900 -1.627 0.104
L1.Niederösterreich 0.192880 0.038886 4.960 0.000
L1.Oberösterreich 0.294132 0.037302 7.885 0.000
L1.Salzburg 0.115255 0.019804 5.820 0.000
L1.Steiermark 0.099660 0.025926 3.844 0.000
L1.Tirol 0.116331 0.021027 5.532 0.000
L1.Vorarlberg 0.070672 0.018079 3.909 0.000
L1.Wien -0.027332 0.033260 -0.822 0.411
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.126832 0.050124 2.530 0.011
L1.Burgenland -0.051500 0.033747 -1.526 0.127
L1.Kärnten -0.040494 0.017969 -2.254 0.024
L1.Niederösterreich 0.169899 0.070582 2.407 0.016
L1.Oberösterreich 0.137069 0.067707 2.024 0.043
L1.Salzburg 0.285179 0.035946 7.933 0.000
L1.Steiermark 0.034461 0.047058 0.732 0.464
L1.Tirol 0.165016 0.038166 4.324 0.000
L1.Vorarlberg 0.104166 0.032815 3.174 0.002
L1.Wien 0.071498 0.060370 1.184 0.236
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060277 0.039719 1.518 0.129
L1.Burgenland 0.038850 0.026741 1.453 0.146
L1.Kärnten 0.050740 0.014239 3.563 0.000
L1.Niederösterreich 0.225797 0.055930 4.037 0.000
L1.Oberösterreich 0.282378 0.053651 5.263 0.000
L1.Salzburg 0.051428 0.028484 1.805 0.071
L1.Steiermark -0.007722 0.037289 -0.207 0.836
L1.Tirol 0.149598 0.030243 4.946 0.000
L1.Vorarlberg 0.070840 0.026003 2.724 0.006
L1.Wien 0.078774 0.047838 1.647 0.100
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.177231 0.047470 3.734 0.000
L1.Burgenland -0.005840 0.031960 -0.183 0.855
L1.Kärnten -0.061190 0.017018 -3.596 0.000
L1.Niederösterreich -0.083981 0.066845 -1.256 0.209
L1.Oberösterreich 0.192065 0.064122 2.995 0.003
L1.Salzburg 0.057299 0.034043 1.683 0.092
L1.Steiermark 0.230414 0.044566 5.170 0.000
L1.Tirol 0.494288 0.036145 13.675 0.000
L1.Vorarlberg 0.049640 0.031077 1.597 0.110
L1.Wien -0.047730 0.057174 -0.835 0.404
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.162168 0.054497 2.976 0.003
L1.Burgenland -0.011393 0.036691 -0.311 0.756
L1.Kärnten 0.065911 0.019537 3.374 0.001
L1.Niederösterreich 0.200303 0.076740 2.610 0.009
L1.Oberösterreich -0.061043 0.073613 -0.829 0.407
L1.Salzburg 0.216493 0.039082 5.539 0.000
L1.Steiermark 0.113629 0.051163 2.221 0.026
L1.Tirol 0.077210 0.041496 1.861 0.063
L1.Vorarlberg 0.124556 0.035678 3.491 0.000
L1.Wien 0.114217 0.065637 1.740 0.082
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.353569 0.031759 11.133 0.000
L1.Burgenland 0.005702 0.021382 0.267 0.790
L1.Kärnten -0.023593 0.011385 -2.072 0.038
L1.Niederösterreich 0.223812 0.044721 5.005 0.000
L1.Oberösterreich 0.175192 0.042899 4.084 0.000
L1.Salzburg 0.047463 0.022776 2.084 0.037
L1.Steiermark -0.016644 0.029816 -0.558 0.577
L1.Tirol 0.108935 0.024182 4.505 0.000
L1.Vorarlberg 0.073801 0.020792 3.550 0.000
L1.Wien 0.052996 0.038251 1.385 0.166
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041219 0.152591 0.190025 0.157497 0.124417 0.113898 0.065559 0.226856
Kärnten 0.041219 1.000000 -0.002657 0.129767 0.041531 0.096005 0.429471 -0.053136 0.101112
Niederösterreich 0.152591 -0.002657 1.000000 0.336867 0.154478 0.300401 0.111123 0.183808 0.327994
Oberösterreich 0.190025 0.129767 0.336867 1.000000 0.232180 0.332634 0.172683 0.172482 0.262667
Salzburg 0.157497 0.041531 0.154478 0.232180 1.000000 0.145766 0.127235 0.148952 0.134324
Steiermark 0.124417 0.096005 0.300401 0.332634 0.145766 1.000000 0.153471 0.140940 0.079062
Tirol 0.113898 0.429471 0.111123 0.172683 0.127235 0.153471 1.000000 0.115023 0.154981
Vorarlberg 0.065559 -0.053136 0.183808 0.172482 0.148952 0.140940 0.115023 1.000000 0.007174
Wien 0.226856 0.101112 0.327994 0.262667 0.134324 0.079062 0.154981 0.007174 1.000000